#include "arduinoDisplayVoltage.h"
#include <LiquidCrystal.h>

LiquidCrystal lcd( 12, 11, 5, 4, 3, 7 );

#define ANALOG_IN_PIN 0
#define LOOP_DELAY 100
#define PIN_MIN 0
#define PIN_MAX 1023
#define VOLTS_MIN 0.00
#define VOLTS_MAX 17.05

double pinToVolts( int nPinVal )
{
  double nReturn = ( ( (double) ( VOLTS_MAX - VOLTS_MIN ) / (double) ( PIN_MAX - PIN_MIN ) ) * (double) nPinVal );

  return nReturn;
}

void setup()
{
  lcd.begin(16,2);
  Serial.begin( 115200 );
  analogReference( INTERNAL );
}

void loop()
{
  int nRawAnalogReadVal = analogRead( ANALOG_IN_PIN );

  Serial.print( "sensor = " );
  lcd.clear();
  lcd.print("Sensor: ");
  Serial.print( nRawAnalogReadVal );
  lcd.print(nRawAnalogReadVal);
  Serial.print( " Voltage=" );
  lcd.setCursor(0,1);
  lcd.print("Voltage: ");
  Serial.println( pinToVolts( nRawAnalogReadVal) );
  lcd.print(pinToVolts( nRawAnalogReadVal));

  delay( LOOP_DELAY );
}
